import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;

public class Task01 {
	public static void main(String[] args) {

		// warm-up
		for (int i = 0; i < 1_000; i++) {
			arrayListVsLinkedList(false);
		}

		arrayListVsLinkedList(true);
	}

	private static void arrayListVsLinkedList(boolean verbose) {
		List<String> arrayList = new ArrayList<>();
		List<String> linkedList = new LinkedList<>();

		if (verbose)
			System.out.println("#e\tt_ll\tt_al\tt_ll - t_al");

		for (int i = 0; i < 10_000; i++) {
			String randString = getRandomString();
			long arrayListTime = benchmarkPrependStringToList(randString,
					arrayList);
			long linkedListTime = benchmarkPrependStringToList(randString,
					linkedList);

			if (verbose)
				System.out.printf("%d\t%d\t%d\t%d%n", i, linkedListTime,
						arrayListTime, linkedListTime - arrayListTime);
		}
	}

	private static long benchmarkPrependStringToList(String string,
			List<String> list) {
		long start = System.nanoTime();
		
		list.add(0, string);
		
		long stop = System.nanoTime();
		return stop - start;
	}

	private static String getRandomString() {
		return String.format("foo%f", Math.random());
	}
}
